package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.mapper.MenuMapper;
import com.itheima.pojo.Menu;
import com.itheima.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service(interfaceClass = MenuService.class)
public class MenuServiceImpl implements MenuService {

    @Autowired
    private MenuMapper menuMapper;

    @Override
    public List<Menu> findMenuByUsername(String username) {
        List<Menu> menuList = menuMapper.findMenuByUsername(username);
        for (Menu menu : menuList) {
            String path = menu.getPath();
            List<Menu> childMenu = menuMapper.findMenuByUsername2(path);
            menu.setChildren(childMenu);
        }
        return menuList;
    }
}
